package question2;


import java.util.Random;

public class Task {
    private int taskId;

    private int param;

    public Task(int taskId, int param) {
        this.taskId = taskId;
        this.param = param;
    }

    public int doTask(Worker worker) {
        // https://blog.csdn.net/weixin_40612082/article/details/102588193  java中 random seed 使用
        int costTime = (1 + new Random().nextInt(5)) * 10;
        try {
            String beginInfo = String.format("工人(workId:%s)开始任务(taskId:%s, Param:%s).", worker.getWorkerId(), taskId, param);
            System.out.println(beginInfo);
            Thread.sleep(costTime);
//            String finishInfo = String.format("工人(Id:%s)完成任务(Id:%s), 耗时：%s 毫秒.", worker.getWorkerId(), taskId, costTime);
//            System.out.println(finishInfo);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return param * param;
    }

    public int getTaskId() {
        return taskId;
    }

    public void setTaskId(int taskId) {
        this.taskId = taskId;
    }

    public int getParam() {
        return param;
    }

    public void setParam(int param) {
        this.param = param;
    }
}
